package com.company.finance.ddd.interfaces;

import com.company.finance.ddd.domain.core.bill.aggregate.BillAggregate;
import com.company.finance.ddd.domain.core.bill.service.QueryBillService;
import com.company.finance.ddd.interfaces.dto.BillDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 *
 * @author wanglei
 * @version $$Id: BillApi, v 0.1 2021/2/19 14:22 wanglei Exp $$
 */
@RequestMapping("/bill")
@RestController
public class BillApi {

    @Resource
    private QueryBillService queryBillService;

    @GetMapping("get/{id}")
    public BillDTO getBill(@PathVariable Long id) {
        QueryBillService.QueryCondition condition = new QueryBillService.QueryCondition();
        condition.setId(id);
        BillAggregate billAggregate = queryBillService.get(id);
        if (null == billAggregate) {
            return null;
        }
        BillDTO dto = new BillDTO();
        BeanUtils.copyProperties(billAggregate, dto);
        return dto;
    }
}
